﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using $prjsn$.Business.Services;
using $prjsn$.Common.Business.Services;

using ProjectBase.Core;
using $safeprojectname$.Infrastructure.Factories;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using ProjectBase.Mvc;

namespace $safeprojectname$.Core.Extensions
{

    [TestClass]
    public class MessageHolderTest : TestBase
    {
        [TestMethod]
        public void Exception_FilledInMessage_Passed()
        {
            var provider = ProviderFactory.ProviderWithMessageHandler();
            var holder = FacadeFactory.CreateFacade<IUserFacade>();

            provider.Publish(holder, "ExceptionMessage", new Exception("MyException"));

            Assert.IsTrue(holder.Messages.First().Severity == Severity.Error);
            Assert.IsTrue(holder.Messages.First().Reporter == "User");
            Assert.IsTrue(holder.Messages.First().Text == "ExceptionMessage");
        }

        [TestMethod]
        public void Object_FilledInMessage_Passed()
        {
            var provider = ProviderFactory.ProviderWithMessageHandler();
            var holder = FacadeFactory.CreateFacade<IUserFacade>();

            provider.Publish(holder, () => "MyInformation", Severity.Info);

            Assert.IsTrue(holder.Messages.First().Severity == Severity.Info);
            Assert.IsTrue(holder.Messages.First().Reporter == "User");
            Assert.IsTrue(holder.Messages.First().Text == "MyInformation");
        }

        [TestMethod]
        public void Delegate_FilledInMessage_Passed()
        {
            var provider = ProviderFactory.ProviderWithMessageHandler();
            var holder = FacadeFactory.CreateFacade<IUserFacade>();

            provider.Publish(holder, Severity.Warning, "MyWarning to {0}", "World");

            Assert.IsTrue(holder.Messages.First().Severity == Severity.Warning);
            Assert.IsTrue(holder.Messages.First().Reporter == "User");
            Assert.IsTrue(holder.Messages.First().Text.EndsWith("MyWarning to World"));
        }

        #region Init

        // You can use the following additional attributes as you write your tests:

        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }

        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }

        [TestInitialize]
        public override void MyTestInitialize()
        {
            base.MyTestInitialize(); // Use TestInitialize to run code before running each test
        }

        [TestCleanup]
        public override void MyTestCleanup()
        {
            base.MyTestCleanup(); // Use TestCleanup to run code after each test has run
        }
        #endregion Init
    }
}
